﻿using MeetSomeNearbyStranger.DataLayer;
using MeetSomeNearbyStrangerWebApi.Controllers;
using MeetSomeNearbyStrangerWebApi.Repositories;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web.Http.Dependencies;

namespace MeetSomeNearbyStrangerWebApi.Resolvers
{
    public class DbDependencyResolver : IDependencyResolver
    {
        public DbDependencyResolver()
        {
        }

        public IDependencyScope BeginScope()
        {
            return this;
        }

        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(UsersController))
            {
                DbContext context = new DataContext();
                DbUsersRepository usersRepository = new DbUsersRepository(context);
                DbMeetsRepository meetsRepository = new DbMeetsRepository(context);
                DropboxUploader uploader = new DropboxUploader();
                PubNubSender pubnub = new PubNubSender();
                return new UsersController(usersRepository, uploader, meetsRepository, pubnub);
            }
            if (serviceType == typeof(MeetsController))
            {
                DbContext context = new DataContext();
                DbUsersRepository usersRepository = new DbUsersRepository(context);
                DbMeetsRepository meetsRepository = new DbMeetsRepository(context);
                PubNubSender pubnub = new PubNubSender();
                return new MeetsController(usersRepository, meetsRepository, pubnub);
            }
            
            return null;
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return new List<object>();
        }

        public void Dispose() { }
    }
}